#include<cstdio>
#include<cstring>

using namespace std;

const int maxn=110000;
int next[maxn],n;
char p[maxn],p1[maxn];
void make_next()
{
	int k=0;
	next[0]=0;
	n=strlen(p+1);
	for(int i=2;i<=n;i++)
	{
		while(k>0&&p[k+1]!=p[i])
			k=next[k];
		if(p[k+1]==p[i])k++;
		next[i]=k;
	}
}

int main()
{
	while(scanf("%s",p+1)!=EOF)
	{
		scanf("%s",p1+1);
		int n1=strlen(p+1);
		int n2=strlen(p1+1);
		p[n1+1]='A';
		for(int i=1;i<=n2;i++)
			p[n1+i+1]=p1[i];
		p[n1+1+n2+1]='\0';
		memset(next,0,sizeof(next));
		make_next();
		p[next[n]+1]='\0';
		if(next[n]>0)
		printf("%s %d\n",p+1,next[n]);
		else printf("0\n");
	}
	return 0;
}

